package com.catmiao.spark.rdd.operator.action

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_action
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/22 22:47
 */
object RDD_Operator_02_action {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)

    val rdd = sparkContext.makeRDD(List(2,1,3,4))


    /**
     * reduce 直接聚合出结果
     */

    //    val result = rdd.reduce(_ + _)
    //    println("result:",result)

    val result: Array[Int] = rdd.collect()
    println(result.toList.mkString(","))

    println(rdd.count())

    println(rdd.first())

    println(rdd.take(2).toList.mkString(","))

    println(rdd.takeOrdered(2)(Ordering.Int.reverse).toList.mkString(","))


    sparkContext.stop()

  }

}
